#include <QTextDocument>
#include "notification.h"
#include "notification-background.h"
#include "ui_notification.h"


Notification::Notification (const QPixmap& backgroundImage, QWidget* parent) :
    QWidget(parent), ui(new Ui::Notification)
{
    ui->setupUi(this);
    setWindowOpacity(0.00);
    setWindowFlags(Qt::ToolTip | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
    setAttribute(Qt::WA_TranslucentBackground, true);
    notificationBackground = new NotificationBackground(backgroundImage, this);

    QFont font = ui->labelMessage->font();
    font.setPointSize(font.pointSize() + 1);
    ui->labelMessage->setFont(font);
    font.setBold(true);
    ui->labelTitle->setFont(font);
}


void Notification::setTitle (const QString& title)
{
    ui->labelTitle->setText(title);
}


void Notification::setMessage (const QString &message)
{
    if (Qt::mightBeRichText(message))
    {
        // workaround for displaying custom color for hyperlinks in QLabel
        // there's no custom color visited hyperlink, because QLabel doesn't track it
        QString newMessage("<html><style>a { color: white; }</style><body>");
        newMessage.append(message);
        newMessage.append("</body></html>");
        ui->labelMessage->setText(newMessage);
    }
    else
    {
        ui->labelMessage->setText(message);
    }
}


void Notification::setImage (const QPixmap& image)
{
    ui->labelImage->setPixmap(image);
}


void Notification::setOpacity (const qreal& level)
{
    setWindowOpacity(level);
}


qreal Notification::getOpacity() const
{
    return windowOpacity();
}


void Notification::moveRequest (const int& x, const int& y)
{
    move(x, y);
    emit widgetMoved();
}


Notification::~Notification()
{
    delete notificationBackground;
}
